﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace Dragon.Prototype1.Infrastructure.Controls
{
    public class RadioBox : jQueryControl
    {
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Input;
            }
        }

        public RadioBox(string name):this(name,false)
        { 
        
        }

        public RadioBox(string name,bool isChecked)
        {
            this.Name = name;
            this.IsChecked = isChecked;
            this.Selector = string.Format("input[name={0}]", name);
            RadioBoxStyleName = "jquery-ryanfait-radio-red";
        }
        public bool IsChecked
        {
            get;
            set;
        }

        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "radio");
            if (IsChecked)
                writer.AddAttribute(HtmlTextWriterAttribute.Checked, "true");
            base.AddAttributesToRender(writer);
        }
        [jQueryParameter("cls")]
        public string RadioBoxStyleName
        {
            get;
            set;
        }
        public override void RenderJavaScriptContents(HtmlTextWriter writer)
        {
            base.RenderJavaScriptContents(writer);
            writer.WriteLine(string.Format("$(\"{0}\").checkbox({1});", this.Selector, GeneratejQueryParameterArray()));
        }
    }
}
